<?php
// +----------------------------------------------------------------------
// | 公共Action控制器父类
// +----------------------------------------------------------------------
// | @link ( http://www.yurnero.net )
// +----------------------------------------------------------------------
// | @copyright
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author Haijun Wu <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: BaseAction.class.php 115 2011-05-11 09:06:41Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class BaseAction extends Action {

	//初始化接口
	public function _initialize() {
		
		if (!$_SESSION[C('USER_AUTH_KEY')]) {
			//跳转到认证网关
			redirect(PHP_FILE.C('USER_AUTH_GATEWAY'));
		}
		
		/* 验证是否超时登录 */
		$this->checkOnline();
			
		/* 对用户传入的变量进行去除转义操作。*/
		all_stripslashes();
	
		/* 载入系统参数 */
		global $_CFG; 
		$_CFG = get_config();
		
		/* 评论表情 */
		smilies_init();	
		
		/* 创建静态缓存文件 */
		import("@.ORG.StaticCaches");
		$cache = new StaticCaches();
		$cache->cacheInit();
		//create_static_caches();
		
		header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
		header('Cache-Control: no-cache, must-revalidate');
		header('Pragma: no-cache');

		/* 判断是否支持gzip模式 */
		if (gzip_enabled()) {
			ob_start('ob_gzhandler');
		} else {
			ob_start();
		}
		
		/* 清除文件状态缓存 */
		clearstatcache();
		
		/* 插件导入 */
		require_cache (ROOT_PATH.'Public/Plugins/fml/fml.php');		
	}
	
	//验证是否超时登录,默认1800s
	protected function checkOnline($online='1800') {
		$nowtime = gmtime();
		if ($nowtime - $_SESSION['user_logintime'] > $online) {
			$this->assign('jumpUrl',__APP__.'/Admin/login/');
			$this->success(L('login_online'));
		} else {
			$_SESSION['user_logintime'] = gmtime();
		}
	}
	
	//检查用户是否登录
	protected function checkUser() {
		if (!isset($_SESSION[C('USER_AUTH_KEY')])) {
			$this->assign('jumpUrl',__APP__.'/Admin/login/');
			$this->error(L('login_first'));
		}
	}
	
	//检查权限
	protected function checkLimits() {
		if ($_SESSION['user_level'] != 0) {
			$this->error(L('no_limits'));
		}
	}
	
	//空操作
	public function _empty() {
		$this->assign('jumpUrl',__APP__);
		$this->error(L('illegal'));
	}
	
}

?>